package com.zzw.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zzw.entity.User;
import com.zzw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import com.zzw.web.JsonResult;
import com.zzw.web.ResultCode;

@RestController
@RequestMapping("/api/admin")
/**
 * @Athor:xiezhongjiang
 * @Description:管理接口：登录……等
 * @Date:2017/10/30 17:10
 * @Since:1.0.0
 */
public class AdminController {

    //@Value("${spring.profiles}")
    //private String env;
    @Autowired
    private UserService userService;
    private String userName = "admin";
    private String pw = "123456";

    @RequestMapping(value = "/login" )
    /**
    * @Athor:xiezhongjiang
    * @Description:TODO
    * @Date:2017/10/31 11:55
    * @Param:[request, response用于保存token到cookie中 map包含userName和password]
    * @return com.zzw.web.JsonResult
    */
    public JsonResult login(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, String> map) {
        User user = new User();
        user.setId(1);
        user.setUsername("admin");
        user.setPassword("123456");
        if (userName.equals(map.get("userName")) && pw.equals(map.get("password"))) {
            return new JsonResult(ResultCode.SUCCESS, "登录成功！", user);
        } else {
            return new JsonResult(ResultCode.NOT_LOGIN, "登录失败！", user);
        }
    }
}
